package com.sina.shop.controller.async;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * 段浩杰   2018-01-08-10:24
 */
@Service("asyncService")
public class AsyncService {

    protected final Logger LOG = LoggerFactory.getLogger(this.getClass());

    @Async
    public void Task1(String id) {
        Long beginTime = System.currentTimeMillis();
        for (int i = 0; i < 20 * 20; i++) {
            long sum = i * i * i * i;
        }
        Long endTime = System.currentTimeMillis();

        LOG.info("task1--time:{},threadName:{}", endTime - beginTime, Thread.currentThread().getName());
    }

    @Async
    public void Task2(String id) {
        Long beginTime = System.currentTimeMillis();
        for (int i = 0; i < 30 * 30; i++) {
            long sum = i * i * i * i;
        }
        Long endTime = System.currentTimeMillis();

        LOG.info("task2--time:{},threadName:{}", endTime - beginTime, Thread.currentThread().getName());
    }

    @Async
    public void Task3(String id) {
        Long beginTime = System.currentTimeMillis();
        for (int i = 0; i < 40 * 40; i++) {
            long sum = i * i * i * i;
        }
        try {
            Thread.sleep(1000);
        } catch (Exception e) {

        }

        Long endTime = System.currentTimeMillis();

        LOG.info("task3--time:{},threadName:{}", endTime - beginTime, Thread.currentThread().getName());
    }

}
